package com.woniuxy02;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;

/**
 * @author 作者
 * @create 2025-11-05 16:59
 */
public class Test03 {
    public static void main(String[] args) {
        //判断二月有多少天
        //时间设置为3月1号，-1天就是二月的最后的一天，判断是本月的几天
        Calendar calendar = Calendar.getInstance();
        for (int year=2000;year<=2030;year++) {
            calendar.set(year,2, 1);
            calendar.add(Calendar.DATE, -1);
            System.out.println(calendar.get(Calendar.DATE));
        }

    }

    private static void test06() {
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);
        dateTime = dateTime.plusYears(1);
        System.out.println(dateTime);

        dateTime = dateTime.plus(1, ChronoUnit.HOURS);
        System.out.println(dateTime);
        System.out.println(dateTime.getDayOfMonth());
    }

    private static void test05() {
        LocalDateTime dateTime=LocalDateTime.now();
        System.out.println(dateTime.getYear());
        System.out.println(dateTime.getMonth());
        System.out.println(dateTime.getMonthValue());
        System.out.println(dateTime.getDayOfMonth());
        dateTime.get(ChronoField.YEAR);
        dateTime.get(ChronoField.MONTH_OF_YEAR);
        dateTime.get(ChronoField.DAY_OF_MONTH);
        dateTime.get(ChronoField.DAY_OF_WEEK);
        dateTime.get(ChronoField.DAY_OF_YEAR);
    }

    private static void test04() {
        String str="2025-11-05 17:12:12";
        DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(str, dtf);
        System.out.println(dateTime);
    }

    private static void test03() {
        //LocalDateTime转String
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);
        //DateTimeFormatter指定日期格式
//        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String str = dtf.format(dateTime);
        System.out.println(str);
    }

    private static void test02() {
        LocalDateTime dateTime = LocalDateTime.of(2000, 1, 2, 12, 20, 30);
        System.out.println(dateTime);
    }

    private static void test01() {
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);
        LocalDate date = LocalDate.now();
        System.out.println(date);
        LocalTime time = LocalTime.now();
        System.out.println(time);
    }
}
